Migrate Oracle SQL functions and procedures to PostgreSQL#4
Migrate Oracle SQL functions and procedures to PostgreSQL#4
Conversation
Co-authored-by: wgzhao <1001616+wgzhao@users.noreply.github.com>
Co-authored-by: wgzhao <1001616+wgzhao@users.noreply.github.com>
src/main/resources 目录有两个子目录functions 和 procedures ,他们分别存储了基于 Oracle 的函数和存储过程 SQL 文件。请讲这两个子目录的 SQL,迁移到 postgresql 数据库上。|
postgresql has not schema |
Co-authored-by: wgzhao <1001616+wgzhao@users.noreply.github.com>
Removed all STG01 schema references from the PostgreSQL migration files. All 16 files have been updated to work without schema prefixes, making them compatible with PostgreSQL's approach. (commit 3cdc1fd) |
|
the file |
The |
|
@wgzhao 请问一下这个的迁移思路是啥呢? |
Overview
This PR migrates all Oracle-based SQL functions and stored procedures in the
src/main/resourcesdirectory to PostgreSQL-compatible versions, addressing the requirement to support PostgreSQL as an alternative database backend.Changes Made
Functions Migrated (11 files)
functions/fn_imp_comment_replace.sql→fn_imp_comment_replace_pg.sqlfunctions/fn_imp_freqchk.sql→fn_imp_freqchk_pg.sqlfunctions/fn_imp_param_replace.sql→fn_imp_param_replace_pg.sqlfunctions/fn_imp_pnname.sql→fn_imp_pnname_pg.sqlfunctions/fn_imp_pntype.sql→fn_imp_pntype_pg.sqlfunctions/fn_imp_timechk.sql→fn_imp_timechk_pg.sqlfunctions/fn_imp_value.sql→fn_imp_value_pg.sqlfunctions/getltd.sql→getltd_pg.sqlfunctions/getntd.sql→getntd_pg.sqlfunctions/getparam.sql→getparam_pg.sqlfunctions/gettd.sql→gettd_pg.sqlProcedures Migrated (4 new files)
proceduers/sp_imp_deal.sql→sp_imp_deal_pg.sqlproceduers/sp_imp_flag.sql→sp_imp_flag_pg.sqlproceduers/sp_imp_status.sql→sp_imp_status_pg.sqlproceduers/sp_sms.sql→sp_sms_pg.sqlNote:
sp_imp_alone_pg.sqlandsp_imp_param_pg.sqlalready existedKey Transformations Applied
Syntax Changes
CREATE OR REPLACE PROCEDURE→CREATE OR REPLACE FUNCTION ... RETURNS voidAS BEGIN ... END;→AS $$ BEGIN ... END; $$ LANGUAGE plpgsqlIN/OUT) → PostgreSQLDEFAULTsyntaxRESULT_CACHEhintsData Type Mapping
VARCHAR2→VARCHARCLOB→TEXTNUMBER→NUMERIC/INTEGERFunction Replacements
NVL()→COALESCE()DECODE()→CASE WHENchr(10)→E'\n'instr()→position()wm_concat()→string_agg()sysdate→CURRENT_TIMESTAMPXMLAGG→string_agg()ROWID→ PostgreSQLCTIDQuery Syntax
SELECT ... FROM DUAL→SELECT ...MINUS→EXCEPTEXECUTE IMMEDIATE→EXECUTE||)Example Migration
Before (Oracle):
After (PostgreSQL):
Compatibility
_pg.sqlsuffix for easy identificationTesting
fn_imp_valueand procedures likesp_imp_dealhave been successfully convertedThis migration enables the application to run on PostgreSQL databases while maintaining full backward compatibility with existing Oracle deployments.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.